home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 23 / develop Issue 23 code / ProjectDrag 1.1b8 / Sources / ProjectDrag Sources / TasksAndErrors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-24  |  6.0 KB  |  254 lines  |  [TEXT/MPS ]

  1. /* TasksAndErrors.h: Task and error notification routines for ProjectDrag
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13. #include <Dialogs.h>
  14. #include <Errors.h>
  15. #include <LowMem.h>
  16. #include <ToolUtils.h>
  17.  
  18. #include "PDUtilities.h"
  19. #include "TasksAndErrors.h"
  20. #include "DSGlobals.h"
  21.  
  22.  
  23. #define    kResTextAlertID    207
  24.  
  25. #define kStatusWindow 210
  26. #define kStatusInfo 1
  27. #define kStatusText 3
  28.  
  29.  
  30. typedef struct TaskStackEntry
  31. {
  32.     struct TaskStackEntry *fNext;
  33.     Str255 fMessage;
  34. } TaskStackEntry;
  35.  
  36.  
  37. typedef struct PersistentAnswerRecord
  38. {
  39.     struct PersistentAnswerRecord *fNext;
  40.     short fStrListID;
  41.     short fStrIndex;
  42.     ConfirmResponse fAnswer;
  43. } PersistentAnswerRecord;
  44.  
  45.  
  46. static DialogPtr pStatusWindow;
  47. static OSErr pTaskError;
  48. static Str255 pTaskErrorString;
  49. static Boolean pHaveErrorNumber = false;
  50. static Boolean pHaveErrorString = false;
  51. static TaskStackEntry *pTaskStack = NULL;
  52. static PersistentAnswerRecord *pPersistentAnswer = NULL;
  53.  
  54.  
  55. static void ResTextErrorAlert(short strListID, short strIndex, OSErr callerErr,
  56.                                StringPtr param1, StringPtr param2,
  57.                                StringPtr param3, StringPtr param4);
  58.  
  59.  
  60. static void InstallStatusWindow(void) 
  61. {
  62.     if (pStatusWindow == NULL)
  63.     {
  64.         short type;
  65.         Handle h;
  66.         Rect r;
  67.         Str255 s;
  68.                 
  69.         pStatusWindow = GetNewDialog(kStatusWindow, NULL, (WindowPtr)-1);
  70.         GetDItem(pStatusWindow, kStatusInfo, &type, &h, &r);
  71.         ReplaceInIndString(s, kProjectDragStrings, kTimsByline, LMGetCurApName(),
  72.                             NULL, NULL, NULL);
  73.         SetIText(h, s);
  74.         ShowWindow(pStatusWindow);
  75.         DrawDialog(pStatusWindow);
  76.     }
  77. }
  78.  
  79.  
  80. void SetStatusMessage(StringPtr message)
  81. {
  82.     short type;
  83.     Handle h;
  84.     Rect r;
  85.     Str255 s;
  86.     unsigned char nullString[1];
  87.     
  88.     if (pStatusWindow == NULL)
  89.         InstallStatusWindow();
  90.  
  91.     GetDItem(pStatusWindow, kStatusText, &type, &h, &r);
  92.     GetIText(h, s);
  93.     if (message == NULL)
  94.     {
  95.         nullString[0] = 0;
  96.         message = nullString;
  97.     }
  98.     if (!EqualString(message, s, true, true))
  99.         SetIText(h, message);
  100. }
  101.  
  102.  
  103. void TaskStart(short strListID, short strIndex, StringPtr param1, StringPtr param2,
  104.                 StringPtr param3, StringPtr param4)
  105. {
  106.     Str255 message;
  107.     TaskStackEntry *theEntry;
  108.     
  109.     ReplaceInIndString(message, strListID, strIndex, param1, param2, param3, param4);    
  110.     SetStatusMessage(message);
  111.     
  112.     /* push the task string onto the task stack */
  113.     theEntry = (TaskStackEntry*)NewPtr(sizeof(TaskStackEntry));
  114.     /* XXX uh-oh if there's no memory */
  115.     BlockMoveData(message, theEntry->fMessage, message[0] + 1);
  116.     theEntry->fNext = pTaskStack;
  117.     pTaskStack = theEntry;
  118. }
  119.  
  120.  
  121. void TaskDone(void)
  122. {
  123.     /* pop the task from the task stack */
  124.     TaskStackEntry *theEntry = pTaskStack;
  125.     pTaskStack = pTaskStack->fNext;
  126.     DisposePtr((Ptr)theEntry);
  127.     
  128.     if (pTaskStack != NULL)
  129.     {
  130.         SetStatusMessage(pTaskStack->fMessage);
  131.     }
  132.     else if (!gDone)
  133.     {
  134.         /* put nothing in the status window */
  135.         SetStatusMessage(NULL);
  136.     }
  137. }
  138.  
  139.  
  140. void PopAllTasks(void)
  141. {
  142.     /* if there was an error, show the alert */
  143.     if (pHaveErrorNumber)
  144.     {
  145.         if (pTaskError != userCanceledErr)
  146.             ResTextErrorAlert(kProjectDragStrings, kAnErrorOccured, pTaskError,
  147.                               pTaskStack->fMessage, NULL, NULL, NULL);
  148.     }
  149.     else if (pHaveErrorString)
  150.     {
  151.         ResTextErrorAlert(kProjectDragStrings, kAnErrorOccured, pTaskError,
  152.                             pTaskStack->fMessage, pTaskErrorString, NULL, NULL);
  153.     }
  154.     pHaveErrorNumber = pHaveErrorString = false;
  155.     
  156.     /* delete the task stack */
  157.     while (pTaskStack)
  158.     {
  159.         TaskStackEntry *theEntry = pTaskStack;
  160.         pTaskStack = pTaskStack->fNext;
  161.         DisposePtr((Ptr)theEntry);
  162.     }
  163.     
  164.     /* delete the persistent answer list */
  165.     while (pPersistentAnswer)
  166.     {
  167.         PersistentAnswerRecord *theEntry = pPersistentAnswer;
  168.         pPersistentAnswer = pPersistentAnswer->fNext;
  169.         DisposePtr((Ptr)theEntry);
  170.     }
  171.     
  172.     /* put nothing in the status window */
  173.     SetStatusMessage(NULL);
  174. }
  175.  
  176.  
  177. OSErr RaiseErrorNumber(OSErr err)
  178. {
  179.     /* mark the error for PopAllTasks to show */
  180.     pHaveErrorNumber = true;
  181.     pTaskError = err;
  182.     return err;
  183. }
  184.  
  185.  
  186. void RaiseErrorString(short strListID, short strIndex,
  187.                        StringPtr param1, StringPtr param2,
  188.                        StringPtr param3, StringPtr param4)
  189. {
  190.     /* mark the error for PopAllTasks to show */
  191.     pHaveErrorString = true;
  192.     ReplaceInIndString(pTaskErrorString, strListID, strIndex,
  193.                        param1, param2, param3, param4);
  194. }
  195.  
  196.  
  197. void ResTextErrorAlert(short strListID, short strIndex, OSErr callerErr,
  198.                        StringPtr param1, StringPtr param2,
  199.                        StringPtr param3, StringPtr param4)
  200. {
  201.     Str255 message;
  202.     Str255 errorString;
  203.     
  204.     if (callerErr != noErr)
  205.         NumToString (callerErr, errorString);
  206.     else
  207.         errorString[0] = 0;
  208.     ReplaceInIndString(message, strListID, strIndex, param1, param2, param3, param4);    
  209.     ParamText(message, errorString, NULL, NULL);
  210.     (void) Alert ( kResTextAlertID, NULL );
  211. }
  212.  
  213.  
  214. void PersistentAnswer(short strListID, short strIndex, ConfirmResponse answer)
  215. {
  216.     /* search the list for this entry */
  217.     PersistentAnswerRecord *theEntry;
  218.     for (theEntry = pPersistentAnswer; theEntry != NULL; theEntry = theEntry->fNext)
  219.     {
  220.         if (theEntry->fStrListID == strListID && theEntry->fStrIndex == strIndex)
  221.         {
  222.             /* found it */
  223.             theEntry->fAnswer = answer;
  224.             return;
  225.         }
  226.     }
  227.     
  228.     /* didn't find it, add one */
  229.     theEntry = (PersistentAnswerRecord*)NewPtrClear(sizeof(PersistentAnswerRecord));
  230.     if (theEntry == NULL) return;
  231.     theEntry->fStrListID = strListID;
  232.     theEntry->fStrIndex = strIndex;
  233.     theEntry->fAnswer = answer;
  234.     theEntry->fNext = pPersistentAnswer;
  235.     pPersistentAnswer = theEntry;
  236. }
  237.  
  238.  
  239. Boolean GetPersistentAnswer(short strListID, short strIndex, ConfirmResponse *answer)
  240. {
  241.     /* search the list for this entry */
  242.     PersistentAnswerRecord *theEntry;
  243.     for (theEntry = pPersistentAnswer; theEntry != NULL; theEntry = theEntry->fNext)
  244.     {
  245.         if (theEntry->fStrListID == strListID && theEntry->fStrIndex == strIndex)
  246.         {
  247.             /* found it */
  248.             *answer = theEntry->fAnswer;
  249.             return true;
  250.         }
  251.     }
  252.     return false;
  253. }
  254.